package com.ruoyi.web.controller.quality;

import java.util.Collection;
import java.util.List;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;

import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.core.validate.QueryGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.quality.domain.vo.QualityClassificationPartVo;
import com.ruoyi.quality.domain.bo.QualityClassificationPartBo;
import com.ruoyi.quality.service.IQualityClassificationPartService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 零件类型
 *
 * @author ruoyi
 * @date 2023-12-22
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/quality/classificationPart")
public class QualityClassificationPartController extends BaseController {

    private final IQualityClassificationPartService iQualityClassificationPartService;

    /**
     * 查询零件类型列表
     */
    @SaCheckPermission("quality:classificationPart:list")
    @GetMapping("/list")
    public TableDataInfo<QualityClassificationPartVo> list(QualityClassificationPartBo bo, PageQuery pageQuery) {
        return iQualityClassificationPartService.queryPageList(bo, pageQuery);
    }

    /**
     * 查询零件类型列表
     */
    @SaCheckPermission("quality:classificationPart:list")
    @GetMapping("/listAll")
    public List<QualityClassificationPartVo> listAll(QualityClassificationPartBo bo, PageQuery pageQuery) {
        return iQualityClassificationPartService.queryList(bo);
    }

    /**
     * 导出全部零件类型列表
     */
    @SaCheckPermission("quality:classificationPart:export")
    @Log(title = "零件类型", businessType = BusinessType.EXPORT)
    @PostMapping("/exportAll")
    public void exportAll(QualityClassificationPartBo bo, HttpServletResponse response) {
        List<QualityClassificationPartVo> list = iQualityClassificationPartService.queryList(bo);
        ExcelUtil.exportExcel(list, "零件类型", QualityClassificationPartVo.class, response);
    }

    /**
     * 导出选择零件类型列表
     */
    @SaCheckPermission("quality:classificationPart:export")
    @Log(title = "零件类型", businessType = BusinessType.EXPORT)
    @PostMapping("/exportSelect/{ids}")
    public void exportSelect(@NotEmpty(message = "主键不能为空")
                                 @PathVariable Collection<Long> ids, HttpServletResponse response) {
        List<QualityClassificationPartVo> list = iQualityClassificationPartService.queryByIds(ids);
        ExcelUtil.exportExcel(list, "零件类型", QualityClassificationPartVo.class, response);
    }

    /**
     * 获取零件类型详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("quality:classificationPart:query")
    @GetMapping("/{id}")
    public R<QualityClassificationPartVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(iQualityClassificationPartService.queryById(id));
    }

    /**
     * 新增零件类型
     */
    @SaCheckPermission("quality:classificationPart:add")
    @Log(title = "零件类型", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody QualityClassificationPartBo bo) {
        return toAjax(iQualityClassificationPartService.insertByBo(bo));
    }

    /**
     * 修改零件类型
     */
    @SaCheckPermission("quality:classificationPart:edit")
    @Log(title = "零件类型", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody QualityClassificationPartBo bo) {
        return toAjax(iQualityClassificationPartService.updateByBo(bo));
    }

    /**
     * 删除零件类型
     *
     * @param ids 主键串
     */
    @SaCheckPermission("quality:classificationPart:remove")
    @Log(title = "零件类型", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(iQualityClassificationPartService.deleteWithValidByIds(Arrays.asList(ids), true));
    }
}
